package com.lolo.sso.controller;

import com.lolo.sso.common.Constant;
import com.lolo.sso.execption.TokenMissingException;
import com.lolo.sso.vo.CommonResult;
import com.lolo.sso.vo.CreateOrganReqParam;
import com.lolo.sso.vo.Oauth2ResParam;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/unitrust")
public class OrganController {

    @PostMapping("/org/create")
    public CommonResult createOrgan(@RequestHeader(value = "UniTrust-Token", required = false) String token,
                                    @RequestHeader(value = "UniTrust-AppId", required = false) String appId,
                                    @RequestBody CreateOrganReqParam reqParam) {
        if (token == null || token.isEmpty()) {
            throw new TokenMissingException("请求头中缺少 token");
        }
        if (appId == null || appId.isEmpty()) {
            throw new TokenMissingException("请求头中缺少 appId");
        }
        if (!token.equals(Constant.db_random_token)) {
            throw new TokenMissingException("无效的token");
        }
        return CommonResult.ok();
    }

    @PostMapping("/api/data")
    public String postData(@RequestHeader(value = "UniTrust-Token", required = false) String token,
                           @RequestHeader(value = "UniTrust-AppId", required = false) String appId) {
        if (token == null || token.isEmpty()) {
            throw new TokenMissingException("请求头中缺少 token");
        }
        if (appId == null || appId.isEmpty()) {
            throw new TokenMissingException("请求头中缺少 appId");
        }
        if (!token.equals(Constant.db_random_token)) {
            throw new TokenMissingException("无效的token");
        }

        return "数据已接收";
    }
}
